package com.example.chat2.dao;

import com.example.chat2.domain.PriMessageDetail;
import com.example.chat2.domain.Schoolchat;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PriMessageMapper {
    @Select("SELECT pm.id3 AS id3, pm.id4 AS id4, pm.pri_text AS priText, pm.pri_image AS priImage, sc1.id AS id3_sc1, sc1.username AS username_id3, sc1.photo AS photo_id3, sc2.id AS id4_sc2, sc2.username AS username_id4, sc2.photo AS photo_id4 " +
            "FROM pri_message pm " +
            "LEFT JOIN schoolchat sc1 ON pm.id3 = sc1.id " +
            "LEFT JOIN schoolchat sc2 ON pm.id4 = sc2.id")
    @Results({
            @Result(property = "id3", column = "id3"),
            @Result(property = "id4", column = "id4"),
            @Result(property = "priText", column = "priText"),
            @Result(property = "priImage", column = "priImage"),
            @Result(property = "schoolchat1", column = "id3_sc1", javaType = Schoolchat.class, one = @One(
                    select = "com.example.chat2.dao.SchoolchatMapper.findSchoolchatById"
            )),
            @Result(property = "schoolchat2", column = "id4_sc2", javaType = Schoolchat.class, one = @One(
                    select = "com.example.chat2.dao.SchoolchatMapper.findSchoolchatById"
            ))
    })
    List<PriMessageDetail> findPriMessageDetailsWithSchoolchats();
}